import Vue from "vue";
import Vuex from "vuex";
import { parseTime } from "@/utils/hongke";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    theme: "light",
    dateSel: "",
    searchType: "1",
    //   事件下拉框的值
    levelCodeList: [],
    typeCodeList: [],
    categoryCodeList: [],
    protectCodeList: [
      { label: "未处置", value: "0" },
      { label: "已处置", value: "1" },
    ],
    equipmentStatusList: [],
    secLevelList: [],
    equipmentTypeList: [],
    useStatusList:[]
  },
  getters: {},
  mutations: {
    changeTheme(state) {
      if (state.theme == "light") {
        state.theme = "dark";
      } else {
        state.theme = "light";
      }
    },
    changeDate(state, date) {
      let end = new Date();
      let start = new Date();
      switch (date) {
        case "day":
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
          state.searchType = "1";
          break;
        case "week":
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
          state.searchType = "2";
          break;
        case "month":
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
          state.searchType = "3";
          break;
        default:
      }
      // console.log('改变开始时间========',start)
      state.dateSel = [
        parseTime(start, "{y}-{m}-{d}T{h}:{i}:{s}"),
        parseTime(end, "{y}-{m}-{d}T{h}:{i}:{s}"),
      ];
    },
    //   设置字典项的值
    SETEVENTDICT(state, query) {
      switch (query.param) {
        case "event_level":
          state.levelCodeList = query.value.map((i) => {
            return { label: i.normalName, value: i.normalCode };
          });
          // console.log('888888888',state.levelCodeList)
          break;
        case "event_type":
          state.typeCodeList = query.value.map((i) => {
            return { label: i.normalName, value: i.normalCode };
          });
          break;
        case "event_category":
          state.categoryCodeList = query.value.map((i) => {
            return { label: i.normalName, value: i.normalCode };
          });
          break;
      }
    },
    // 设置资产部分
    ASSETSDICT(state, query) {
      switch (query.param) {
        case "equipmentType":
          state.equipmentTypeList = query.value.map((i) => {
            return { label: i.itemLabel, value: i.itemVale };
          });
          break;
        case "equipmentSecLevel":
          state.secLevelList = query.value.map((i) => {
            return { label: i.itemLabel, value: i.itemVale };
          });
          break;
        case "equipmentStatus":
          state.equipmentStatusList = query.value.map((i) => {
            return { label: i.itemLabel, value: i.itemVale };
          });
          break;
        case "equipmentUseStatus":
          state.useStatusList = query.value.map((i) => {
            return { label: i.itemLabel, value: i.itemVale };
          });
          break;
      }
    },
  },
  actions: {
    //  查询事件字典
    getEventDict({ commit }, query) {
      // groupTag({ groupType: query }).then((res) => {
      //   commit("SETEVENTDICT", { param: query, value: res });
      // });
    },
    getAssetsDict({ commit }, query) {
      // dictQuery(query).then((res) => {
       
      //   commit("ASSETSDICT", { param: query, value: res });
      // });
    },
  },
  modules: {},
});
